package pl.edu.agh.mobsys.data;

import java.io.Serializable;

import android.content.SharedPreferences;

/**
 * konfiguracja serwera
 * */
public class ConnectionConfig implements Serializable {

	private static final long serialVersionUID = 1L;

	public String host, port, username, password, resource, ip;

	public final static String KEY_PREFIX = "pl.edu.agh.mobsys.data.cc.";

	public static ConnectionConfig readFromSharedPreferences(
			final SharedPreferences sp) {
		ConnectionConfig cc = new ConnectionConfig();
		cc.ip = sp.getString(KEY_PREFIX + "ip", "10.0.2.2");
		cc.host = sp.getString(KEY_PREFIX + "host", "10.0.2.2");
		cc.port = sp.getString(KEY_PREFIX + "port", "5222");
		cc.username = sp.getString(KEY_PREFIX + "username", "");
		cc.password = sp.getString(KEY_PREFIX + "password", "");
		cc.resource = sp.getString(KEY_PREFIX + "resource", "");
		return cc;
	}

	public void persistInsideSharedPreferences(final SharedPreferences sp) {
		sp.edit().putString(KEY_PREFIX + "ip", ip).putString(KEY_PREFIX + "host", host).putString(
				KEY_PREFIX + "port", port).putString(KEY_PREFIX + "username",
				username).putString(KEY_PREFIX + "password", password)
				.putString(KEY_PREFIX + "resource", resource).commit();
	}
}
